package com.loco.handsomemo.lib_keyboard;

import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;

/**
 * date :2018/7/10
 * author: lzh
 * description:
 * version:
 */
public class KeyboardTouchListener implements View.OnTouchListener {
    private CWKeyboardUtil keyboardUtil;
    private int keyboardType = 1;
    private int scrollTo = -1;

    public KeyboardTouchListener(CWKeyboardUtil util, int keyboardType, int scrollTo) {
        this.keyboardUtil = util;
        this.keyboardType = keyboardType;
        this.scrollTo = scrollTo;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (keyboardUtil != null) {
                if (keyboardUtil.getEd() != null && v.getId() != keyboardUtil.getEd().getId())
                    keyboardUtil.showKeyBoardLayout((EditText) v, keyboardType, scrollTo);
                else if (keyboardUtil.getEd() == null) {
                    keyboardUtil.showKeyBoardLayout((EditText) v, keyboardType, scrollTo);
                } else {
                    keyboardUtil.setKeyBoardCursorNew((EditText) v);
                }
            }
        }
        return false;
    }
}
